.global print_number
.text
#expects a signed integer in $g0
print_number:
	ori $t0 $zero 1
	slli $t0 $t0 31
	and $t0 $t0 $g0
	eqi $t0 $t0 0 # $t0 is nonzero if $g0 is positive
	ji $t0 print_number_positive # if we have a positive number, don't bother 
	ori $t1 $zero 45             # printing a minus sign
	wr $t1 1
	neg $g0 $g0 # now $g0 is positive
	print_number_positive: # recursive calls will point here
	subi $sp $sp 2
	addi $t0 $sp 0
	st $ra $t0
	addi $t0 $sp 1
	st $g1 $t0

	or $g1 $zero $g0
	divi $g0 $g1 10
	cali $g0 print_number_positive
	
	modi $g0 $g1 10
	cali $sp print_digit

	addi $t0 $sp 0
	ld $ra $t0
	addi $t0 $sp 1
	ld $g1 $t0
	addi $sp $sp 2
	j $sp $ra
	
	
# expects a number [0-9] in $g0
print_digit:
	addi $g0 $g0 48
	wr $g0 1
	j $sp $ra

